<?php

namespace Database\Factories;

use App\Models\Administrator;
use Dcat\Admin\Models\Role;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;

class AdministratorFactory extends Factory
{

    protected $model = Administrator::class;

    /**
     * Define the model's default state.
     *
     * @return array
     */
    public function definition()
    {
        return [
            'name'           => $this->faker->name(),
            'username'       => $this->faker->lastName,
            'password'       => '$2y$10$/.mmfw9Wn6IVzfOsh1TCJeQIlpcGUA7ldMzP5FDismFAtyxOmpD7W', // admin
            'remember_token' => Str::random(10),
        ];
    }


    public function administrator(): AdministratorFactory
    {
        return $this->afterCreating(function (Administrator $administrator) {
            // 在这里，你可以访问新创建的 $administrator 实例，
            // 并给它分配角色和权限。

            // 假设你正在使用 Spatie 的 Laravel-permission 包，
            // 你可以像这样分配角色和权限：

            $role = Role::create(['name' => 'Administrator', 'slug' => 'administrator']);
            $administrator->roles()->attach($role);

            return $administrator;
        });
    }
}
